﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Domain.PermisosModule.Entities;
using Cesave.Infrastructure.Data.Core;
using Cesave.Domain.PermisosModule.Contracts.Modulos;
using Cesave.Infrastructure.Data.PermisosModule.Context;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Domain.Core.Specification;

namespace Cesave.Infrastructure.Data.PermisosModule.Repositories
{
	public class ModuloRepository
		: GenericRepositoryEx<Modulo>, IModuloRepository
	{
		#region Constructor

		/// <summary>
		/// 
		/// </summary>
		/// <param name="context"></param>
		/// <param name="traceManager"></param>
		public ModuloRepository(IPermisosModuleContext context, ITraceManager traceManager)
			: base(context, traceManager)
		{
		}

		#endregion

		#region IModuloRepository Members

		/// <summary>
		/// 
		/// </summary>
		/// <param name="modulosByJuntaSpecification"></param>
		/// <returns></returns>
		public IEnumerable<Modulo> FindModulosByJunta(ModulosByJuntaSpecification modulosByJuntaSpecification)
		{
			if (modulosByJuntaSpecification == null)
				throw new ArgumentNullException("modulosByJuntaSpecification");
			return GetBySpec(modulosByJuntaSpecification).OrderBy(m => m.Nombre);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="modulosByJuntaSpecification"></param>
		/// <param name="modulosByStatusSpecification"></param>
		/// <returns></returns>
		public IEnumerable<Modulo> FindModulosByJuntaAndStatus(ModulosByJuntaSpecification modulosByJuntaSpecification, ModulosByStatusSpecification modulosByStatusSpecification)
		{
			if (modulosByJuntaSpecification == null)
				throw new ArgumentNullException("modulosByJuntaSpecification");
			if (modulosByStatusSpecification == null)
				throw new ArgumentNullException("modulosByStatusSpecification");
			Specification<Modulo> specification = new TrueSpecification<Modulo>();
			specification &= modulosByJuntaSpecification;
			specification &= modulosByStatusSpecification;
			return GetBySpec(specification).OrderBy(m => m.Nombre);
		}

		#endregion
	}
}
